package main

import (
	"fmt"
	"math"
	"radar/nimrod/util"
	"unsafe"
)

func main() {
	// test()

	filePath := `E:\experiment\Go\dat\metoffice-c-band-rain-radar_hameldon-hill_200809291459_raw-polar-ref-el0.dat`
	outputFilePath := `F:\research\data_assimilation\result\radar\nimrod\preprocessing\metoffice-c-band-rain-radar_hameldon-hill_200809291459_raw-polar-ref-el0.ref`
	util.WriteNimrodFileHeader(filePath, outputFilePath)

	// inDir := `E:\experiment\Go\dat`
	// outDir := `F:\research\data_assimilation\result\radar\nimrod\preprocessing`
	// err := util.Write2WRFDA(inDir, outDir)
	// if err != nil {
	// 	fmt.Println(err)
	// 	os.Exit(1)
	// }
}

func test() {
	type Metric struct {
		Tag string
		num int
	}
	var ms = []*Metric{
		{
			Tag: "1",
			num: 0,
		},
		{
			Tag: "2",
			num: 1,
		},
		{
			Tag: "3",
			num: 2,
		},
		{
			Tag: "阿萨德",
			num: 2,
		},
	}
	for _, m := range ms {
		fmt.Println(m)
	}
	for i, m := range ms {
		if m.Tag == "1" {
			m.Tag = "中文"
		} else {
			ms[i].Tag = "0"
		}
	}

	for _, m := range ms {
		fmt.Println(m)
	}

}

func sqrt(x float64) float64 {
	switch {
	case x == 0 || isNaN(x) || isInf(x, 1):
		return x
	case x < 0:
		return NaN()
	}
	var z = x
	for {
		tem := z - (math.Pow(z, 2)-x)/(2*z)
		if z-tem < 0.00000001 {
			return z
		}
		z = tem

	}
}
func isNaN(f float64) (is bool) {
	// IEEE 754 says that only NaNs satisfy f != f.
	// To avoid the floating-point hardware, could use:
	//	x := Float64bits(f);
	//	return uint32(x>>shift)&mask == mask && x != uvinf && x != uvneginf
	return f != f
}
func isInf(f float64, sign int) bool {
	// Test for infinity by comparing against maximum float.
	// To avoid the floating-point hardware, could use:
	//	x := Float64bits(f);
	//	return sign >= 0 && x == uvinf || sign <= 0 && x == uvneginf;
	return sign >= 0 && f > math.MaxFloat64 || sign <= 0 && f < -math.MaxFloat64
}

// NaN returns an IEEE 754 ``not-a-number'' value.
func NaN() float64                     { return float64frombits(0x7FF8000000000001) }
func float64frombits(b uint64) float64 { return *(*float64)(unsafe.Pointer(&b)) }
